#include "../Require/Init.iss"
function main()
{
	extension -require isxeq2
	;EA "Loading" "Loot.iss"
	if !${Me.InCombat} && !${FullInventory}
	{
		if ${NextTarget} != 0
		{
			if ${Actor[${NextTarget}].Type.Equal[Chest]}
			{
				EQ2Echo Chest detected : ${Actor[${NextTarget}].Name}
				Target "${NextTarget}"
				wait 2
				call MoveToTargetMelee
				switch ${Me.Class}
				{
					case dirge
					case troubador
					case swashbuckler
					case brigand
					case ranger
					case assassin
						Echo disarming trap on ${Target.ID}
						EQ2Execute "/apply_verb ${Target.ID} disarm"
						wait 20
						break
					case default
						break
				}
				Actor[Chest]:DoubleClick
				wait 5
				call LootWindow
				wait 5
			}
			elseif ${Actor[${NextTarget}].Type.Equal[Corpse]}
			{
				EQ2Echo Corpse detected : ${Actor[${NextTarget}].Name}
				Target "${NextTarget}"
				wait 2
				call MoveToTargetMelee
				Actor[corpse]:DoubleClick
				wait 5
				call LootWindow
				wait 5
				
			}
			call ClearTarget
			NextTarget:Set[0]
		}
	}
}
function LootWindow()
{
	declare LootCount uint local 0
	EQ2UIPage[Inventory,Loot].Child[button,Loot.button RequestAll]:LeftClick 
	wait 20 

	if !${EQ2UIPage[Hud,Choice].Child[text,Choice.Text].Label.Find[DEVL]} 
	{ 
	     	LootCount:Set[1] 
	     	do 
	     	{ 
			EQ2UIPage[Hud,Choice].Child[button,Choice.Choice1]:LeftClick
			
		} 
		while ${LootCount:Inc} <= ${LootWindow.NumItems} 
	}
}
function atexit()
{
	;VirtualState:Set[ROAM]
	;EA "Unloading" "Loot.iss"
}
